<template>
  <div>
    <div v-if="showCloudList" class="flex-grid-layout">
      <div v-for="(item,index) in aliCloud.content" :key="index" class="cloud-item link-item"
           @click="onCloudItemClick(item)">
        <div class="header-view">{{ item.content[0] }}</div>
      </div>
    </div>
    <div v-else class="ver-layout">
      <div class="hor-layout-center">
        <div class="cloud-detail-header">{{ cloudItem[0] }}</div>
        <el-button type="primary" size="small" style="position: absolute;right: 30%"
                   @click="showCloudList=true">
          返回
        </el-button>
      </div>
      <div v-if="haveSubTitle" class="ver-layout">
        <div v-for="(item,index) in cloudDetail" :key="index"
             class="cloud-item-line" :class="{'link-item':isCloudItemLink(item)}"
             @click="toCloudPage(item)">
          {{ getItemContent(item) }}
        </div>
      </div>
      <div v-else class="flex-grid-layout">
        <div v-for="(item,index) in cloudDetail" :key="index"
             class="cloud-item" :class="{'link-item':isCloudItemLink(item)}"
             @click="toCloudPage(item)">
          {{ getItemContent(item) }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import aliCloud from "../../assets/getAliPath.json"

export default {
  name: "index",
  data() {
    return {
      aliCloud,
      cloudItem: [],
      showCloudList: true,
      cloudUrl: ""
    }
  },
  computed: {
    cloudDetail() {
      return this.cloudItem.slice(1)
    },
    haveSubTitle() {//有二级标题
      return this.cloudItem.length && this.cloudItem[0].indexOf("考公/考编/考研资料") != -1
    }
  },
  mounted() {

  },
  methods: {
    onCloudItemClick(item) {
      this.cloudItem = item.content
      this.showCloudList = false
    },
    getItemContent(item) {
      return item.split("https://www")[0]
    },
    isCloudItemLink(item) {
      return item.indexOf("https://") != -1
    },
    toCloudPage(item) {
      let cloudPath = item.substring(item.indexOf("https://www"))
      console.log("cloudPath", cloudPath)
      if (cloudPath.indexOf("https://") != -1)
        window.open(cloudPath, "_blank");
    }
  }
}
</script>

<style scoped>
.cloud-item {
  font-weight: bold;
  padding: 10px;
  margin: 10px;
  background: lightgrey;
  width: 22%;
}

.cloud-item-line {
  padding: 10px;
}

.link-item {
  color: #3a8ee6;
}

.header-view {

}

.cloud-detail-header {
  font-size: 18px;
  font-weight: bold;
  margin: 10px auto;
}
</style>
